<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta charset="utf-8" />
<base href="<%=basePath%>">

<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>商品管理</title>
<!-- Tell the browser to be responsive to screen width -->
<meta
	content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"
	name="viewport">
<link rel="stylesheet" href="seller/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="seller/plugins/adminLTE/css/AdminLTE.css">
<link rel="stylesheet"
	href="seller/plugins/adminLTE/css/skins/_all-skins.min.css">
<link rel="stylesheet" href="seller/css/style.css">
<script src="seller/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="seller/plugins/bootstrap/js/bootstrap.min.js"></script>


<script src="seller/plugins/jQuery/jquery-2.2.3.min.js"></script>

<script src="seller/plugins/Paging/js/paging.js"></script>

<!-- <script src="seller/Paging/js/paging.js"></script>
 -->

<style>
			* {
				padding: 0;
				margin: 0;
			}
			/*
			  * 外面盒子样式---自己定义
			  */
			
			.page_div {
				margin-top: 300px;
				margin-bottom: 20px;
				position:relative;
				font-size: 15px;
				font-family: "microsoft yahei";
				color: #666666;
				margin-right: 10px;
				padding-left: 100px;
				box-sizing: border-box;
				
			}
			/*
			 * 页数按钮样式
			 */
			
			.page_div a {
				min-width: 30px;
				height: 28px;
				border: 1px solid #dce0e0!important;
				text-align: center;
				margin: 0 4px;
				cursor: pointer;
				line-height: 28px;
				color: #666666;
				font-size: 13px;
				display: inline-block;
			}
			
			#firstPage,
			#lastPage {
				width: 50px;
				color: #0073A9;
				border: 1px solid #0073A9!important;
			}
			
			#prePage,
			#nextPage {
				width: 70px;
				color: #0073A9;
				border: 1px solid #0073A9!important;
			}
			
			.page_div .current {
				background-color: #0073A9;
				border-color: #0073A9;
				color: #FFFFFF;
			}
			
			.totalPages {
				margin: 0 10px;
			}
			
			.totalPages span,
			.totalSize span {
				color: #0073A9;
				margin: 0 5px;
			}
		</style>
		
	<!-- 	
		<script>
	
	
		//分页
		function  xc() {
				
				var num=1;
				$("#page").paging({
					
					pageNo : num, //页号
					totalPage : Math.ceil(${pageResult.total} / 5),
					totalSize : ${pageResult.total},
					callback : function(page) {
					window.location.href="goods/findGoods.action?pageNum="+page+"&pageSize=5";
					num=page;
					}
				});
		
			}
			
	</script>
	 -->
		
		
</head>

<body class="hold-transition skin-red sidebar-mini" style="position: absolute;">
	<!-- .box-body -->

	<div class="box-header with-border">
		<h3 class="box-title">商品管理</h3>
	</div>

	<div class="box-body">

		<!-- 数据表格 -->
		<div class="table-box">

			<!--工具栏-->
			<div class="pull-left">
				<div class="form-group form-inline">
					<div class="btn-group">
						<button type="button" class="btn btn-default" title="新建">
							<i class="fa fa-file-o"></i> 新建
						</button>
						<button type="button" class="btn btn-default" title="删除" onclick="deleteGoods()">
							<i class="fa fa-trash-o"></i> 删除
						</button>
						<button type="button" onclick="commit()" class="btn btn-default" title="提交审核">
							<i class="fa fa-check"></i> 提交审核
						</button>
						<button type="button" class="btn btn-default" title="上架"
							onclick="putortake('put')">
							<i class="fa fa-ban"></i> 上架
						</button>
						<button type="button" class="btn btn-default" title="下架"
							onclick="putortake('take')">
							<i class="fa fa-ban"></i> 下架
						</button>
						
						<button type="button" class="btn btn-default" title="刷新"
							onclick="window.location.reload();">
							<i class="fa fa-refresh"></i> 刷新
						</button>
					</div>
				</div>
			</div>
			<div class="box-tools pull-right">
				<div class="has-feedback">
					状态：<select onchange="searchstatus(value)">
					
						<option value="">全部</option>
						<option value="0">未申请</option>
						<option value="1">申请中</option>
						<option value="2">审核通过</option>
						<option value="3">已驳回</option>
						<option value="4">未上架</option>
						<option value="5">已上架</option>
						<c:if test="${goodsStatus!=null }">
					<script>
						var node=$("option");
						var value=${goodsStatus};
						
						for(var i=0;i<node.length;i++){
							
							if(node[i].value==value)
								//alert("ok");
							   node[i].selected="selected";
						}
					</script>
					</c:if>
					</select> 
					
					
					商品名称：<input id="search"/>
					<button class="btn btn-default" onclick="search()">查询</button>
				</div>
			</div>
			<!--工具栏/-->

			<!--数据列表-->
			<table id="dataList"
				class="table table-bordered table-striped table-hover dataTable">
				<thead>
					<tr>
						<th class="" style="padding-right:0px"><input id="selall"
							type="checkbox" class="icheckbox_square-blue" onclick="check()"></th>
						<th class="sorting_asc">商品ID</th>
						<th class="sorting">商品名称</th>
						<th class="sorting">商品价格</th>
						<th class="sorting">一级分类</th>
						<th class="sorting">二级分类</th>
						<th class="sorting">三级分类</th>
						<th class="sorting">状态</th>
						<th class="sorting">是否上架</th>
						<th class="text-center">操作</th>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${pageResult.rows}" var="row">
				
					<tr>
						<td><input type="checkbox" name="selallson" id="${row.id }"></td>
						<td>${row.id }</td>
						<td>${row.goodsName }</td>
						<td>${row.price}</td>
						<td>${row.category1Id }</td>
						<td>${row.category2Id }</td>
						<td>${row.category3Id }</td>
						<c:choose>
								<c:when test="${row.auditStatus=='0'}">
									<td>未申请</td>
								</c:when>
								<c:when test="${row.auditStatus=='1'}">
									<td>申请中</td>
								</c:when>
								<c:when test="${row.auditStatus=='2'}">
									<td>申请通过</td>
								</c:when>
								<c:when test="${row.auditStatus=='4'}">
									<td>拒绝申请</td>
								</c:when>
								<c:otherwise>
										<td>--</td>
								</c:otherwise>
							</c:choose>
						
							<c:choose>
								<c:when test="${row.isMarketable=='4'}">
									<td>未上架</td>
								</c:when>
								<c:when test="${row.isMarketable=='5'}">
									<td>已上架</td>
								</c:when>
								<c:otherwise>
										<td>--</td>
									</c:otherwise>
							</c:choose>
							
						
						<td class="text-center">
							<button type="button" class="btn bg-olive btn-xs">修改</button>
						</td>
					</tr>
					</c:forEach>
				</tbody>
			</table>
			<!--数据列表/-->


		</div>
		<!-- 数据表格 /-->
		<div value="1 0"></div>
		<div id="page" class="page_div"></div>

	</div>
	<!-- /.box-body -->

</body>
<script type="text/javascript">
			
				
				$("#page").paging({
					
					pageNo :${pageNo}, //页号
					totalPage : Math.ceil(${pageResult.total} / 5),
					totalSize : ${pageResult.total},
					callback : function(page) {
					var node=$("option:selected").val();
					if(node==0||node==1||node==2||node==3){
					window.location.href="goods/findGoods.action?pageNum="+page+"&pageSize=5"+"&auditStatus="+node+"&tag=status";
					} 
					else if(node==4||node==5){
					
					window.location.href="goods/findGoods.action?pageNum="+page+"&pageSize=5"+"&isMarketable="+node+"&tag=status";
					
					}
					
					}
				});
				
				
				
				function check(){
				
				
				$("[name='selallson']").prop("checked",$("#selall").prop("checked"));
				
				}
				
				
			function deleteGoods(){
				
				if(confirm("你确定要删除么")){
				var node=$("[name='selallson']:checked");
				
				 var datavalue="";
				 
					$(node).each(function(index,value){
					datavalue=datavalue+value.getAttribute("id")+",";
					});
					//alert(node.length);
					$.ajax({
					url:"goods/deleteGoods.action",
					data:{goodsId:datavalue},
					success:function(data){
						if(data=='true'){
						alert("删除成功");
						window.location.reload();					
															
						}
						else{
						alert("删除失败，请重新刷新");
						}	
					}
				
				}); 
				
				
		}

}//删除

			function search(){
			//将对象  数组转为json字符串
			//JSON.stringify(对象)
			var value=$("#search").val();
					
				var node=$("option:selected").val();
				if(node==0||node==1||node==2||node==3){
			
					window.location.href="goods/findGoods.action?auditStatus="+node+"&tag=status"+"&goodsName="+value;
			} 
				else{
					window.location.href="goods/findGoods.action?isMarketable="+node+"&tag=market"+"&goodsName="+value;
			
				}		
				//window.location.href="goods/findGoods.action?goodsName="+value;

			}
			
			
			
			function putortake(tag){
			if(tag=='put'){
			
			 if(confirm("确定要上架么？")){
			 var node=$("[name='selallson']:checked"); 
			  
			  var datavalue="";
			  $(node).each(function(index,value){
			  
			  datavalue=datavalue+value.getAttribute("id")+",";
			  
			  
			  });
			 
			  
			  $.ajax({
			  url:"goods/update.action",
			  
			  type:"post",
			  
			  data:{"goodsId":datavalue,"tag":"putaway"},
			  
			  success:function(data){
				  if(data=='true'){
						alert("商品上架成功");
						window.location.reload();					
															
						}
						else{
						alert("商品上架失败！");
						}	
			  
			  }
			  });

		}
		
	}	else{
	
		 if(confirm("确定要下架么？")){
			 var node=$("[name='selallson']:checked"); 
			  
			  var datavalue="";
			  $(node).each(function(index,value){
			  
			  datavalue=datavalue+value.getAttribute("id")+",";
			  
			  
			  });
			 
			  
			  $.ajax({
			  url:"goods/update.action",
			  
			  type:"post",
			  
			  data:{"goodsId":datavalue,"tag":"takeaway"},
			  
			  success:function(data){
				  if(data=='true'){
						alert("商品下架成功");
						window.location.reload();					
															
						}
						else{
						alert("商品下架失败！");
						}	
			  
			  }
			  });

		}
	
	
		}

			}//上下架
			
			
			function commit(){
			if(confirm("确定要提交审核么？")){
			 var node=$("[name='selallson']:checked"); 
			  
			  var datavalue="";
			  $(node).each(function(index,value){
			  
			  datavalue=datavalue+value.getAttribute("id")+",";	  
			  
			  });
			  
			  $.ajax({
			  url:"goods/update.action",
			  
			  type:"post",
			  
			  data:{"goodsId":datavalue,"tag":"commit"},
			  
			  success:function(data){
				  if(data=='true'){
						alert("商品提交审核成功");
						window.location.reload();					
															
						}
						else{
						alert("商品提交审核失败！");
						}	
			  
			  }
			  });
			
			}
		}//提交审核
		
		
		//根据状态查询
		function searchstatus(value){  
		              /*<option value="0">未申请</option>
						<option value="1">申请中</option>
						<option value="2">审核通过</option>
						<option value="3">已驳回</option>
						<option value="4">未上架</option>
						<option value="5">已上架</option> */
		
			
			if(value==0||value==1||value==2||value==3){
			
				window.location.href="goods/findGoods.action?auditStatus="+value+"&tag=status";
			} 
			else{
			window.location.href="goods/findGoods.action?isMarketable="+value+"&tag=market";
			
			}
			
		
		
		}//searchstatus
		
		
	/* 	function checkout(){
		
		if(${goodsStatus!=null}){
			alert("xc");
			var node=$("option");
			for(var i=0;i<node.length;i++){
				if(node[i].value==${goodsStatus}){
				node[i].checked=true;
				}
				
				}
			} 
		}
		
		checkout();
 */

</script>

</html>
